<?php session_start(); 
   if(isset($_SESSION['login'])){
     header('location:index.php');
   }

?>

<?php
   
   if(isset($_POST['submit'])){
   $error=array();
   $required=array('user','pas');
   foreach($required as $namepost){
      if(!isset($_POST[$namepost]) || empty($_POST[$namepost])){
          $error[]="$namepost không được rỗng!";
      }
   }
   if(empty($error)){
      $user=$_POST['user'];
      $pas=$_POST['pas'];
	  echo "'$pas'11111111111111111";
     require_once '../action/DB_MySQL.php';
     $mysql = new DB_MySQL;
     $mysql->connect('localhost', 'baocao', 'root', '');
        $haspas=md5($pas);
		//$haspas=  $strcut=substr($haspas,0,40);
		
		echo "select* from user where user='".$user."' and pas='".$pas."'";
        $mysql->query("select* from user where user='".$user."' and pas='".$pas."'");
        $num_user=$mysql->num_row();
		echo $num_user;
        if($num_user==0){
            $error[]="Tài khoản không tồn tại";
        }else{
              $_SESSION['login']="true";
              
           ?>
           
            <script type="text/javascript">
             window.location = "index.php";
            </script>
    <?php
          
          
        }
       
   }
}

?>
<meta http-equiv="content-type" content="text/html" charset="UTF-8" />
<script src="js/jquery.js" type="text/javascript"></script>
 <script type="text/javascript">
          $(document).ready(function(){
            $('form').hide();
            $('#silie').click(function(){
                $(this).prev('form').slideToggle('normal');
                return false;
            });
          });
        </script>
<div id="login_form">
    <?php
       if(isset($error)&& !empty($error)){
          foreach($error as $loi){
             echo "<ul>";
               echo"<li>$loi</li>";
             echo "</ul>"; 
          }
        
       }
    ?>
    
    
    <link href="css/login.css" rel="stylesheet" type="text/css" />
    <form action="" method="POST" name="login" style="background-color:#2C8493; padding:10px">
       <p>
          <label>Username:</label>
          <input type="text" name="user" id="user" value="<?php if(isset($user)) echo $user?>" />
       </p>
       <p>
          <label>Password:</label>
          <input type="text" name="pas" id="pas" value="<?php if(isset($pas)) echo $pas?>" />
       </p>
       <p>
          <input type="submit" name="submit" value="Login"  id="login"/>
       </p>
    </form>
    <div id="silie" >
      <a>Click here</a>
    </div>
</div>

